package strings

import (
	"bytes"

	"github.com/zfd81/rooster/types/container"
)

const (
	At_Prefix = "at__"
)

func RemoveAt(str string) string {
	var expr bytes.Buffer
	stack := container.NewArrayStack()
	strLen := len(str) //字符串长度
	for i := 0; i < strLen; i++ {
		char := str[i]
		if char == '@' && stack.Empty() {
			expr.WriteString(At_Prefix)
		} else {
			expr.WriteByte(char)
			if char == '\'' || char == '"' {
				if stack.Empty() {
					stack.Push(char)
				} else {
					c, _ := stack.Peek()
					if c == char {
						stack.Pop()
					} else {
						stack.Push(char)
					}
				}
			}
		}
	}
	return expr.String()
}
